package edu.ynu.se.xiecheng.achitectureclass.controller;

import edu.ynu.se.xiecheng.achitectureclass.common.controller.LogicController;
import edu.ynu.se.xiecheng.achitectureclass.dao.ItemDao;
import edu.ynu.se.xiecheng.achitectureclass.dao.LineItemDao;
import edu.ynu.se.xiecheng.achitectureclass.dto.LineItemDTO;
import edu.ynu.se.xiecheng.achitectureclass.entity.Item;
import edu.ynu.se.xiecheng.achitectureclass.entity.LineItem;
import edu.ynu.se.xiecheng.achitectureclass.service.ItemService;
import edu.ynu.se.xiecheng.achitectureclass.service.LineItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Api(tags = "LineItem实体的控制器")
@RestController
@RequestMapping("/lineItem")
public class LineItemController extends LogicController<LineItemService, LineItemDao, LineItem,Long> {
    @Resource
    private ModelMapper modelMapper;

    public LineItemController(@Autowired LineItemService ls){
        super(ls);
    }
    @ApiOperation("查看流水")
    @GetMapping("/browseLineItem/{orderId}")
    public List<LineItemDTO> browseLineItem(@PathVariable Long orderId) {
        List<LineItem> lineItems =  getService().browseLineItem(orderId);
        return lineItems.stream().map(
                ls -> modelMapper.map(ls, LineItemDTO.class)
        ).collect(Collectors.toList());
    }
}
